<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var obj1 = {
            name: "tom",
            age: 20,
            sex: "女"
        };
        var obj2 = {
            name: "王子伟",
            weight: 180,
            show: function () {
                console.log("我正在学习");
            }
        };
        var obj3={
            girl:"刘亦菲"
        };

        // obj2["name"]="值"   obj2.name="值"
        //组合式继承:使用for...in循环
        // for (var key in obj1) {
        //     // console.log(key);//属性名
        //     // console.log(obj1[key]);//属性值
        //     obj2[key] = obj1[key];//obj2['name']="tom"   obj2['age']=20   obj2['sex']="女"

        // }
        // console.log(obj2);
        // console.log(obj1.constructor);//获取对象的构造函数

        //为obj2添加一个方法
        obj2.extend=function(obj){
            for(var key in obj){
                obj2[key]=obj[key];
            }
        };
        obj2.extend(obj1);
        obj2.extend(obj3);
        console.log(obj2);
    </script>
</body>

</html>